package demo;

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/20-07-20-20:07
 * @Description：demo
 */
public class difference {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array1 = new int[n];
        for (int i = 0; i < n; i++) {
            array1[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        Integer[] dif = new Integer[m+1-n];
        int[] array2 = new int[m];
        for (int i = 0; i < m; i++) {
            array2[i] = sc.nextInt();
            if(i >= n-1){
                int temp =0;
                int k =0;
                for(int j = i-n+1; j <= i; j++){

                     temp = temp +  (array2[j]-array1[k])*(array2[j]-array1[k]);
                    k++;
                }
                dif[i-n+1] = temp;
            }
        }
        System.out.println(Collections.min(Arrays.asList(dif)));
    }
}
